package vsvm.data.filter.ranking.rankingStuff;

import java.io.Serializable;

import vsvm.math.statistics.Characteristics;

public class Normalization implements Serializable 
{
	private static final long serialVersionUID = 100L;
	private double min = 0;
	private double max = 1;
	public double getMin() {
		return min;
	}
	public void setMin(double min) {
		this.min = min;
	}
	public double getMax() {
		return max;
	}
	public void setMax(double max) {
		this.max = max;
	}

	private boolean normalize = false;

	public boolean isNormalize() {
		return normalize;
	}
	public void setNormalize(boolean normalize) {
		this.normalize = normalize;
	}
	
	public double[] normalize(double[] vals)
	{		
		double maxA = Characteristics.getMax(vals);
		double minA = Characteristics.getMin(vals);
		double[] normVals = new double[vals.length];	
		
		for(int i = 0; i < vals.length; i++)
		{
			if (Math.abs(maxA - minA) > 1e-8)
			{
				normVals[i] = getMin() + (vals[i] - minA)*(getMax() - getMin())/(maxA - minA);
			}
			else
			{
				normVals[i] = 0.5;	
			}
		}		
		return normVals;
	}
}
